package com.laowang.project.system.controller;

import java.util.Date;
import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.dao.DataAccessResourceFailureException;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.laowang.framework.aspectj.lang.annotation.Log;
import com.laowang.framework.aspectj.lang.enums.BusinessType;

import org.springframework.web.bind.annotation.*;
import com.laowang.project.system.domain.MyBackstageNotice;
import com.laowang.project.system.service.MyBackstageNoticeService;
import com.laowang.framework.web.controller.BaseController;
import com.laowang.framework.web.domain.AjaxResult;
import com.laowang.common.utils.poi.ExcelUtil;
import com.laowang.framework.web.page.TableDataInfo;

/**
 * 公告信息Controller
 *
 * @author laowang
 * @date 2023-06-21
 */
@Api(tags = "公告信息接口")
@RestController
@RequestMapping("/cyhNotice")
public class MyBackstageNoticeController extends BaseController {
    @Autowired
    private MyBackstageNoticeService myBackstageNoticeService;

    /**
     * 获取公告信息详细信息
     */
    @ApiOperation(value = "小程序端 获取公告信息详细信息",notes = "")
    @GetMapping(value = "/web/list")
    public AjaxResult weblist() {
        //没过期的公告
        List<MyBackstageNotice>  myBackstageNotices = myBackstageNoticeService.selectMyBackstageNoticeListWeb(null);

        return AjaxResult.success("操作成功",myBackstageNotices);
    }

    /**
     * 查询公告信息列表
     */
    @ApiOperation(value = "查询公告信息列表",notes = "")
    @PreAuthorize("@ss.hasPermi('my:cyhNotice:list')")
    @GetMapping("/list")
    public TableDataInfo list(MyBackstageNotice myBackstageNotice) {
        startPage();
        List<MyBackstageNotice> list = myBackstageNoticeService.selectMyBackstageNoticeList(myBackstageNotice);
        return getDataTable(list);
    }

    /**
     * 导出公告信息列表
     */
    @ApiOperation(value = "导出公告信息列表",notes = "")
    @PreAuthorize("@ss.hasPermi('my:cyhNotice:export')")
    @GetMapping("/export")
    public AjaxResult export(MyBackstageNotice myBackstageNotice) {
        List<MyBackstageNotice> list = myBackstageNoticeService.selectMyBackstageNoticeList(myBackstageNotice);
        ExcelUtil<MyBackstageNotice> util = new ExcelUtil<MyBackstageNotice>(MyBackstageNotice.class);
        return util.exportExcel(list, "cyhNotice");
    }

    /**
     * 获取公告信息详细信息
     */
    @ApiOperation(value = "获取公告信息详细信息",notes = "")
    @PreAuthorize("@ss.hasPermi('my:cyhNotice:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return AjaxResult.success(myBackstageNoticeService.selectMyBackstageNoticeById(id));
    }

    /**
     * 新增公告信息
     */
    @ApiOperation(value = "新增公告信息",notes = "")
    @PreAuthorize("@ss.hasPermi('my:cyhNotice:add')")
    @PostMapping
    public AjaxResult add(@RequestBody MyBackstageNotice myBackstageNotice) {
        return toAjax(myBackstageNoticeService.insertMyBackstageNotice(myBackstageNotice));
    }

    /**
     * 修改公告信息
     */
    @ApiOperation(value = "修改公告信息",notes = "")
    @PreAuthorize("@ss.hasPermi('my:cyhNotice:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody MyBackstageNotice myBackstageNotice) {
        return toAjax(myBackstageNoticeService.updateMyBackstageNotice(myBackstageNotice));
    }

    /**
     * 删除公告信息
     */
    @ApiOperation(value = "删除公告信息",notes = "")
    @PreAuthorize("@ss.hasPermi('my:cyhNotice:remove')")
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        return toAjax(myBackstageNoticeService.deleteMyBackstageNoticeByIds(ids));
    }
}
